from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column,Integer,String,TIMESTAMP,ForeignKey,UniqueConstraint,Index
from sqlalchemy.orm import sessionmaker, relationship
import pymysql

engine = create_engine("mysql+pymysql://root:Www123...@127.0.0.1:3306/chouti?charset=utf8",max_overflow=5 ) #创建连接

#,max_overflow=5  这个参数是什么意思
# charset=utf8  一定要写

Base = declarative_base()   #指定基类


class UserInfo(Base):       #创建表单
    __tablename__ = "userinfo"   #表单名称
    id = Column(Integer,primary_key=True,autoincrement=True)
    username = Column(String(32))
    pwd = Column(String(18))
    code = Column(String(32))
    stime = Column(TIMESTAMP)
    status = Column(Integer)  # 1,注册用，2 用户存在

    __table_args__ =(
        Index('ix_username_status', 'username', 'status'),
    )



def into_db():
    Base.metadata.create_all(engine)
def drop_db():
    Base.metadata.drop_all(engine)

def session():
    cls = sessionmaker(bind=engine)
    return cls()




if __name__ == '__main__':
    drop_db()
    into_db()
    # ret =session().query(UserInfo).one()


# 指定引擎  增删改 都要用到这些几句  实在是看不明白；
# Session = sessionmaker(bind=engine)
# session = Session()
# session.commit()